package com.glance.browser.dao;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.glance.browser.domain.History;
import com.glance.browser.repository.HistoryRepository;

@Repository
@Transactional(readOnly = true)
public class HistoryDAOImpl implements HistoryDAO {

	@Autowired
	private HistoryRepository repository;

	public Page<History> findByKnowledgeClassId (Long knowledgeClassId, Pageable page) {
		return repository.findByKnowledgeClassId(knowledgeClassId, page);
	}

	public Page<History> findByChangeAuthor (String username, Pageable page) {
		return repository.findByChangeAuthor(username, page);
	}
	
	@Transactional
	public void save(History history){
		repository.save(history);
	}
	
	@Transactional
	public void deleteAll(){
		repository.deleteAll();
	}
	
	@Transactional
	public void deleteAllAfter(long id){
		repository.deleteAllAfter(id);
	}
}
